using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using System.Net;
using ZhCun.Utils.Helpers;
using ZhCun.WebCommon.AL;

namespace ZhCun.WebTemplate.Web
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost
                .CreateDefaultBuilder(args)
                .ConfigureKestrel((context, options) =>
                {
                    options.Listen(IPAddress.Any, AppCommonConfig.AppSettings.HttpPort);
                    if (AppCommonConfig.AppSettings.HttpsPort > 0)
                    {
                        options.Listen(IPAddress.Any, AppCommonConfig.AppSettings.HttpsPort, listenOptions =>
                        {
                            listenOptions.UseHttps(AppCommonConfig.AppSettings.HpptsFileName, AppCommonConfig.AppSettings.HpptsFilePassword);
                        });
                    }
                })                
                .UseStartup<Startup>();
    }
}